//
//  WDWorderOrderWaitVehicleDetailViewModel.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/29.
//

#import "WDWorderOrderWaitVehicleDetailViewModel.h"

@implementation WDWorderOrderWaitVehicleDetailViewModel

- (void)initialize {
    [super initialize];
    self.title = @"工单详情";
}

/// 获取详情
/// - Parameter completion: completion description
- (void)requestWithTaskInfoDetail:(RequestCompletionBlock)completion {
    @weakify(self);
    WDTaskInfoDetailRequest *request = [[WDTaskInfoDetailRequest alloc] initWithTaskId:@(self.serviceModel.id)];
    [request startWithCompletionBlockWithSuccess:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        EDSRespondDataEntity *respond = request.responseModelObject;
        if (respond.code == EDS_NETWORK_SUCCESS) {
            self.taskDetailModel = respond.data;
            
            UIFont *font = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
            float width = kScreenW - 20 * 2 - 102;
            float height = [self.taskDetailModel.detail heightForFont:font width:width];
            height = (height > 18 ? height : 18);
            self.taskDetailModel.detailHeight = height;
            
            for (WDCanFaultInfoModel *ent in self.taskDetailModel.canFaultInfoList) {
                NSString *str = [NSDate timeStampWithString:ent.stimets format:@"yyyy-MM-dd HH:mm:ss"];
                ent.stimetsStr = str;
            }
            
//            NSMutableArray *addList = [NSMutableArray new];
//            WDCanFaultInfoModel *ent = [WDCanFaultInfoModel new];
//            ent.faultName = @"电池故障1";
//            ent.faultCode = @"sn123";
//            ent.stimets = 0;
//            ent.stimetsStr = @"2025-03-08 12:32:23";
//            [addList addObject:ent];
//            ent = [WDCanFaultInfoModel new];
//            ent.faultName = @"电池故障2";
//            ent.faultCode = @"sn423";
//            ent.stimets = 0;
//            ent.stimetsStr = @"2025-03-08 12:32:23";
//            [addList addObject:ent];
//            
//            self.taskDetailModel.canFaultInfoList = [addList copy];
            
            /*
            NSData *jsonData = [self.taskDetailModel.maintainItems dataUsingEncoding:NSUTF8StringEncoding];
            NSError *error = nil;
            id jsonObj = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
            if (!error && jsonObj) {
                NSMutableArray *addList = [NSMutableArray new];
                if ([jsonObj isKindOfClass:[NSArray class]]) {
                    NSArray *list = (NSArray *)jsonObj;
                    for (NSDictionary *dict in list) {
                        MaintainItemModel *model = [MaintainItemModel yy_modelWithJSON:dict];
                        [addList addObject:model];
                    }
                } else if ([jsonObj isKindOfClass:[NSDictionary class]]) {
                    MaintainItemModel *model = [MaintainItemModel yy_modelWithJSON:jsonObj];
                    [addList addObject:model];
                }
                self.taskDetailModel.maintainItemList = addList.copy;
            }
            
            // 维修项目RepairItemModel
            jsonData = [self.taskDetailModel.repairItems dataUsingEncoding:NSUTF8StringEncoding];
            
            jsonObj = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
            if (!error && jsonObj) {
                NSMutableArray *addList = [NSMutableArray new];
                if ([jsonObj isKindOfClass:[NSArray class]]) {
                    NSArray *list = (NSArray *)jsonObj;
                    for (NSDictionary *dict in list) {
                        RepairItemModel *model = [RepairItemModel yy_modelWithJSON:dict];
                        [addList addObject:model];
                    }
                } else if ([jsonObj isKindOfClass:[NSDictionary class]]) {
                    RepairItemModel *model = [RepairItemModel yy_modelWithJSON:jsonObj];
                    [addList addObject:model];
                }
                self.taskDetailModel.repairItemList = addList.copy;
            }*/
            
            /*
            NSMutableArray *addPhoto = [NSMutableArray new];
            WDInspectUploadModel *ent = [WDInspectUploadModel new];
            ent.uploadUrl = @"https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2025%2F0124%2Ff3baf675j00sqkid5000rd000990099g.jpg&thumbnail=140y88&quality=100&type=jpg";
            [addPhoto addObject:ent];
            ent = [WDInspectUploadModel new];
            ent.uploadUrl = @"https://nimg.ws.126.net/?url=http%3A%2F%2Fcms-bucket.ws.126.net%2F2025%2F0124%2F403dd08ep00sqkeie001lc0009c0070c.png&thumbnail=140y88&quality=100&type=jpg";
            [addPhoto addObject:ent];
            ent = [WDInspectUploadModel new];
            ent.uploadUrl = @"https://nimg.ws.126.net/?url=http%3A%2F%2Fcms-bucket.ws.126.net%2F2025%2F0123%2F41260445p00sqjqg30018c0009c0070c.png&thumbnail=140y88&quality=100&type=jpg";
            [addPhoto addObject:ent];
            ent = [WDInspectUploadModel new];
            ent.uploadUrl = @"https://nimg.ws.126.net/?url=http%3A%2F%2Fcms-bucket.ws.126.net%2F2025%2F0123%2F78de9eb8p00sqjmtm001lc0009c0070c.png&thumbnail=140y88&quality=100&type=jpg";
            [addPhoto addObject:ent];
            self.taskDetailModel.problemPhotoList = [addPhoto copy];
            */
            
            
//            WDArrivalServiceDetailModel *md = self.taskDetailModel;
//            NSLog(@"ddd");
            
//            NSMutableArray *addList = [NSMutableArray new];
//            WDBatteryInfoModel *model = [WDBatteryInfoModel new];
//            model.batteryTypeValue = @"卡里锂电池"; // 电池类型
//            WDBatteryModelModel *ent = [WDBatteryModelModel new];
//            model.batteryModel = ent;
//            ent.modelNo = @"KT2424242";// 型号
//            [addList addObject:model];
//            [addList addObject:model];
//            
//            self.taskDetailModel.batteryList = addList.copy;
        }
        [self sendResponseObject:request.responseModelObject completion:completion];
    } failure:^(__kindof TYZBaseRequest * _Nonnull request) {
        @strongify(self);
        [self sendResponseObject:request.responseModelObject completion:completion];
    }];
}

@end
